package com.salon.server.service;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.salon.server.entity.*;
import com.salon.server.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 预约信息表 服务实现类
 * </p>
 *
 * @author zooy
 * @since 2025-08-28
 */
@Service
public class AppointmentService extends ServiceImpl<AppointmentMapper, Appointment> {

    @Autowired
    private ProjectMapper projectMapper;

    @Autowired
    private BeauticianMapper beauticianMapper;

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private MemberMapper memberMapper;

    /**
     * 保存预约信息
     * @param appointment
     */
    public void saveAppointment(Appointment appointment) {

        // 通过项目id，查询项目相关的情况
        Project project = projectMapper.selectById(appointment.getProjectId());
        appointment.setProjectName(project.getName());

        // 查询美容师详情
        Beautician beautician = beauticianMapper.selectById(appointment.getBeauticianId());
        appointment.setBeauticianName(beautician.getName());

        // 查询用户信息
        Integer loginId = Integer.parseInt(StpUtil.getLoginId().toString());
        Member member = memberMapper.selectById(loginId);
        appointment.setMemberId(member.getId());
        appointment.setMemberName(member.getName());
        appointment.setMemberPhone(member.getPhone());

        this.baseMapper.insert(appointment);
    }
}
